from getOhlcV import getOhlcV
import pandas as pd
import os
#直接调用getOhlcV类，对其部分方法进行重写
class getOhlcV_remote(getOhlcV):

    def get_data(self):
        # 数据集已在runclass中传入
        self.filename = os.path.split(self.filepath)[-1]  # 获取文件名，用于输出文件命名
        self.SecID = self.SecDatadf['SecurityID'][0]
        # 如果为深交所数据，则进行数据转换
        if 'ApplSeqNum' in self.SecDatadf.columns:
            self.shen_conversion()

    def SaveData(self, data, filename):
        # 此处的filename仅仅包括文件名和后缀,如'Shcategory.csv'

        # 判断类型是否为DF
        if isinstance(data, pd.DataFrame):
            targetsaveData = data
        else:
            targetsaveData = pd.DataFrame(data)

        # save data
        savefile_AnalystConsForeChange = self.workpath + filename

        if not os.path.exists(savefile_AnalystConsForeChange):  # if not a file the write newone
            targetsaveData.to_csv(savefile_AnalystConsForeChange, mode='w', encoding='utf_8_sig', header=True,
                                  index=False)  # write out a new file with header
        else:

            targetsaveData.to_csv(savefile_AnalystConsForeChange, mode='a', encoding='utf_8_sig', header=False,
                                  index=False)  # write after a exist file without header

    def main_get(self):
        self.get_data()  # 获取数据
        self.Call_auction()  # 处理集合竞价数据
        if len(self.SecDatadf) == 0:
            # 流通性极差无比，连续竞价无交易
            self.data_price = self.CA_price
        else:
            self.data_process()  # 处理数据
            self.side_split()  # 处理组边界
            self.get_Ohlc_data()  # 获取OHLC价格数据
        self.SaveData(self.data_price, str(self.by) + "_" + str(self.method) + "_" + self.filename)  # 统一输出文件名并输出